# -*- coding: utf-8  -*-
# @Time : 2021/8/19  15:39
# @Author : zhangnengbo
# @File : mixup.py
# @Company : HPY

    # If data is for training, perform mixup, only perform mixup roughly on 1 for every 5 images
    if self.train and idx > 0 and idx%5 == 0:

    # Choose another image/label randomly
        mixup_idx = random.randint(0, len(self.data)-1)
        mixup_label = torch.zeros(10)
        label[self.targets[mixup_idx]] = 1.
        if self.transform:
            mixup_image = transform(self.data[mixup_idx])

        # Select a random number from the given beta distribution
        # Mixup the images accordingly
        alpha = 0.2
        lam = np.random.beta(alpha, alpha)
        image = lam * image + (1 - lam) * mixup_image
        label = lam * label + (1 - lam) * mixup_label